package vip.xiaonuo.pm.modular.product.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.param.DeleteByIdParam;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.pm.modular.product.entity.PmProductEntity;
import vip.xiaonuo.pm.modular.product.param.ProductAddParam;
import vip.xiaonuo.pm.modular.product.param.ProductEditParam;
import vip.xiaonuo.pm.modular.product.param.ProductPageParam;
import vip.xiaonuo.pm.modular.product.service.PmProductService;

import java.util.List;

/**
 * <p>
 * 产品表 前端控制器
 * </p>
 *
 * @author xhs
 * @since 2025-06-04
 */
@Tag(name = "产品控制器")
@ApiSupport(author = "SNOWY_TEAM", order = 2)
@Validated
@RestController
@RequestMapping("/pm/product/")
public class PmProductController {

    @Resource
    private PmProductService pmProductService;

    /**
     * 新增产品
     *
     * @param productAddParam 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 1)
    @Operation(summary = "新增产品")
    @CommonLog("新增产品")
    @SaCheckPermission("/pm/product/add")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Validated ProductAddParam productAddParam) {
        pmProductService.add(productAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑产品
     *
     * @param productEditParam 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 2)
    @Operation(summary = "编辑产品")
    @CommonLog("编辑产品")
    @SaCheckPermission("/pm/product/edit")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Validated ProductEditParam productEditParam) {
        pmProductService.edit(productEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除产品
     *
     * @param DeleteIdParamList 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 3)
    @Operation(summary = "删除产品")
    @CommonLog("删除产品")
    @SaCheckPermission("/pm/product/delete")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Validated @NotEmpty(message = "集合不能为空") List<DeleteByIdParam> DeleteIdParamList) {
        pmProductService.delete(DeleteIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取产品分页
     *
     * @param productPageParam 入参
     * @return CommonResult<Page<PmProductEntity>>
     */
    @ApiOperationSupport(order = 4)
    @Operation(summary = "获取产品分页")
    @SaCheckPermission("/pm/product/delete")
    @PostMapping("/page")
    public CommonResult<Page<PmProductEntity>> page(@RequestBody @Validated ProductPageParam productPageParam) {
        return CommonResult.data(pmProductService.page(productPageParam));
    }
}
